package com.jcl.recruit.searchresume.mapper;

import com.jcl.recruit.mapper.provider.SqlProvider;
import com.jcl.recruit.searchresume.model.SearchResumeRecord;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

public class SearchResumeRecordSqlProvider implements SqlProvider<SearchResumeRecord> {

    public String insert(SearchResumeRecord record) {
        BEGIN();
        INSERT_INTO("search_resume_record");
        if (record.getCorpCode() != null) {
            VALUES("corp_code", "#{corpCode,jdbcType=VARCHAR}");
        }

        if (record.getUserId() != null) {
            VALUES("user_id", "#{userId,jdbcType=INTEGER}");
        }

        if (record.getKeyword() != null) {
            VALUES("keyword", "#{keyword,jdbcType=VARCHAR}");
        }

        if (record.getCity() != null) {
            VALUES("city", "#{city,jdbcType=VARCHAR}");
        }

        if (record.getEducation() != null) {
            VALUES("education", "#{education,jdbcType=VARCHAR}");
        }

        if (record.getWorkYear() != null) {
            VALUES("work_year", "#{workYear,jdbcType=INTEGER}");
        }

        if (record.getWechatPush() != null) {
            VALUES("wechat_push", "#{wechatPush,jdbcType=BIT}");
        }

        if (record.getEmailPush() != null) {
            VALUES("email_push", "#{emailPush,jdbcType=BIT}");
        }

        if (record.getStatus() != null) {
            VALUES("status", "#{status,jdbcType=INTEGER}");
        }

        if (record.getCreateTime() != null) {
            VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }

        if (record.getUpdateTime() != null) {
            VALUES("update_time", "#{updateTime,jdbcType=TIMESTAMP}");
        }

        return SQL();
    }

    public String updateByPrimaryKey(SearchResumeRecord record) {
        BEGIN();
        UPDATE("search_resume_record");

        if (record.getUserId() != null) {
            SET("user_id = #{userId,jdbcType=INTEGER}");
        }

        if (record.getCorpCode() != null) {
            SET("corp_code = #{corpCode,jdbcType=VARCHAR}");
        }

        if (record.getKeyword() != null) {
            SET("keyword = #{keyword,jdbcType=VARCHAR}");
        }

        if (record.getCity() != null) {
            SET("city = #{city,jdbcType=VARCHAR}");
        }

        if (record.getEducation() != null) {
            SET("education = #{education,jdbcType=VARCHAR}");
        }

        if (record.getWorkYear() != null) {
            SET("work_year = #{workYear,jdbcType=INTEGER}");
        }

        if (record.getWechatPush() != null) {
            SET("wechat_push = #{wechatPush,jdbcType=BIT}");
        }

        if (record.getEmailPush() != null) {
            SET("email_push = #{emailPush,jdbcType=BIT}");
        }

        if (record.getStatus() != null) {
            SET("status = #{status,jdbcType=INTEGER}");
        }

        if (record.getCreateTime() != null) {
            SET("create_time = #{createTime,jdbcType=TIMESTAMP}");
        }

        if (record.getUpdateTime() != null) {
            SET("update_time = #{updateTime,jdbcType=TIMESTAMP}");
        }

        WHERE("id = #{id,jdbcType=INTEGER}");

        return SQL();
    }
}